<!DOCTYPE html><html lang="zh-CN"><head><meta charset="utf-8"><meta name="X-UA-Compatible" content="IE=edge"><meta name="author" content="imp"><title>Linux基础命令 · imp的个人博客</title><meta name="description" content="Linux基础命令
Linux的目录结构


/，根目录是最顶级的目录了
Linux只有一个顶级目录：/
路径描述的层次关系同样适用/来表示
/home/itheima/a.txt，表示根目录下的home文件夹内有itheima文件夹，内有a.txt

ls命令
功能：列出文件夹信息
语法：ls ["><meta name="keywords" content="imp,blog"><meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport"><meta content="yes" name="apple-mobile-web-app-capable"><meta content="black" name="apple-mobile-web-app-status-bar-style"><meta content="telephone=no" name="format-detection"><meta id="site_root_url" data="/"><meta id="default-theme" data="light"><meta name="renderer" content="webkit"><link rel="shortcut icon" type="image/x-icon" href="/images/icon.png"><link rel="stylesheet" href="/css/theme/light.css"><link rel="stylesheet" href="/css/style.css"><link rel="stylesheet" href="/css/blog_basic.css"><link rel="stylesheet" href="/css/font-awesome.min.css"><link rel="stylesheet" href="/css/insight.css"><link rel="stylesheet" href="/css/search.css"><link rel="alternate" type="application/atom+xml" title="ATOM 1.0" href="/atom.xml"><script src="/js/url_for.js"></script><script src="/js/friends-link-generator.js"></script><script src="/js/jquery.js"></script><script src="/js/jquery-migrate-1.2.1.min.js"></script><script src="/js/jquery.appear.js"></script><script src="/js/site.js"></script><script src="/js/router.js"></script><script src="/js/darkLightToggle.js"></script><script src="/js/add-bookmark.js"></script><meta name="generator" content="Hexo 6.3.0"></head><body><main-outlet><div class="page-top animated"><div class="nav"><li> <a href="/">首页</a></li><li> <a href="/archives">归档</a></li><li> <a href="/tags">标签</a></li><li> <a href="/about">关于</a></li><li> <a href="/links">友链</a></li></div><div class="information"><div class="nav_right_btn"><li><a class="fa fa-chevron-left" onclick="window.history.go(-1)"> </a></li><li><a class="fa fa-search" onclick="openWindow();"></a></li><li><a class="fa fa-sun-o" onclick="darkLightToggle();"></a></li></div><div class="avatar"><img src="/images/logo.webp"></div></div></div><div class="toc-mobile"><div class="toc-button"><span>目录</span></div><div class="toc-container in-page animated fadeInDown"><div class="toclist-container"><div class="tocmenu"><ol class="toclist"><li class="toclist-item toclist-level-1"><a class="toclist-link"><span class="toclist-text">Linux基础命令</span></a><ol class="toclist-child"><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#Linux%E7%9A%84%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84"><span class="toclist-text">Linux的目录结构</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#ls%E5%91%BD%E4%BB%A4"><span class="toclist-text">ls命令</span></a><ol class="toclist-child"><li class="toclist-item toclist-level-3"><a class="toclist-link" href="#%E9%9A%90%E8%97%8F%E6%96%87%E4%BB%B6%E3%80%81%E6%96%87%E4%BB%B6%E5%A4%B9"><span class="toclist-text">隐藏文件、文件夹</span></a></li></ol></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#pwd%E5%91%BD%E4%BB%A4"><span class="toclist-text">pwd命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#cd%E5%91%BD%E4%BB%A4"><span class="toclist-text">cd命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#HOME%E7%9B%AE%E5%BD%95"><span class="toclist-text">HOME目录</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E7%9B%B8%E5%AF%B9%E8%B7%AF%E5%BE%84%E3%80%81%E7%BB%9D%E5%AF%B9%E8%B7%AF%E5%BE%84"><span class="toclist-text">相对路径、绝对路径</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E7%89%B9%E6%AE%8A%E8%B7%AF%E5%BE%84%E7%AC%A6"><span class="toclist-text">特殊路径符</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#mkdir%E5%91%BD%E4%BB%A4"><span class="toclist-text">mkdir命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#touch%E5%91%BD%E4%BB%A4"><span class="toclist-text">touch命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#cat%E5%91%BD%E4%BB%A4"><span class="toclist-text">cat命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#more%E5%91%BD%E4%BB%A4"><span class="toclist-text">more命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#cp%E5%91%BD%E4%BB%A4"><span class="toclist-text">cp命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#mv%E5%91%BD%E4%BB%A4"><span class="toclist-text">mv命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#rm%E5%91%BD%E4%BB%A4"><span class="toclist-text">rm命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#which%E5%91%BD%E4%BB%A4"><span class="toclist-text">which命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#find%E5%91%BD%E4%BB%A4"><span class="toclist-text">find命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#grep%E5%91%BD%E4%BB%A4"><span class="toclist-text">grep命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#wc%E5%91%BD%E4%BB%A4"><span class="toclist-text">wc命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E7%AE%A1%E9%81%93%E7%AC%A6"><span class="toclist-text">管道符|</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#echo%E5%91%BD%E4%BB%A4"><span class="toclist-text">echo命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E5%8F%8D%E5%BC%95%E5%8F%B7"><span class="toclist-text">&#96;反引号</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#tail%E5%91%BD%E4%BB%A4"><span class="toclist-text">tail命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#head%E5%91%BD%E4%BB%A4"><span class="toclist-text">head命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E9%87%8D%E5%AE%9A%E5%90%91%E7%AC%A6"><span class="toclist-text">重定向符</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#vi%E7%BC%96%E8%BE%91%E5%99%A8"><span class="toclist-text">vi编辑器</span></a><ol class="toclist-child"><li class="toclist-item toclist-level-3"><a class="toclist-link" href="#%E5%91%BD%E4%BB%A4%E6%A8%A1%E5%BC%8F%E5%BF%AB%E6%8D%B7%E9%94%AE"><span class="toclist-text">命令模式快捷键</span></a></li><li class="toclist-item toclist-level-3"><a class="toclist-link" href="#%E5%BA%95%E7%BA%BF%E5%91%BD%E4%BB%A4%E5%BF%AB%E6%8D%B7%E9%94%AE"><span class="toclist-text">底线命令快捷键</span></a></li></ol></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E5%91%BD%E4%BB%A4%E7%9A%84%E9%80%89%E9%A1%B9"><span class="toclist-text">命令的选项</span></a><ol class="toclist-child"><li class="toclist-item toclist-level-3"><a class="toclist-link" href="#%E6%9F%A5%E7%9C%8B%E5%91%BD%E4%BB%A4%E7%9A%84%E5%B8%AE%E5%8A%A9"><span class="toclist-text">查看命令的帮助</span></a></li><li class="toclist-item toclist-level-3"><a class="toclist-link" href="#%E6%9F%A5%E7%9C%8B%E5%91%BD%E4%BB%A4%E7%9A%84%E8%AF%A6%E7%BB%86%E6%89%8B%E5%86%8C"><span class="toclist-text">查看命令的详细手册</span></a></li></ol></li></ol></li><li class="toclist-item toclist-level-1"><a class="toclist-link"><span class="toclist-text">Linux常用操作</span></a><ol class="toclist-child"><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E8%BD%AF%E4%BB%B6%E5%AE%89%E8%A3%85"><span class="toclist-text">软件安装</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#systemctl"><span class="toclist-text">systemctl</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E8%BD%AF%E9%93%BE%E6%8E%A5"><span class="toclist-text">软链接</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E6%97%A5%E6%9C%9F"><span class="toclist-text">日期</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E6%97%B6%E5%8C%BA"><span class="toclist-text">时区</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#ntp"><span class="toclist-text">ntp</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#ip%E5%9C%B0%E5%9D%80"><span class="toclist-text">ip地址</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E4%B8%BB%E6%9C%BA%E5%90%8D"><span class="toclist-text">主机名</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E9%85%8D%E7%BD%AEVMware%E5%9B%BA%E5%AE%9AIP"><span class="toclist-text">配置VMware固定IP</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#ps%E5%91%BD%E4%BB%A4"><span class="toclist-text">ps命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#kill%E5%91%BD%E4%BB%A4"><span class="toclist-text">kill命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#nmap%E5%91%BD%E4%BB%A4"><span class="toclist-text">nmap命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#netstat%E5%91%BD%E4%BB%A4"><span class="toclist-text">netstat命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#ping%E5%91%BD%E4%BB%A4"><span class="toclist-text">ping命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#wget%E5%91%BD%E4%BB%A4"><span class="toclist-text">wget命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#curl%E5%91%BD%E4%BB%A4"><span class="toclist-text">curl命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#top%E5%91%BD%E4%BB%A4"><span class="toclist-text">top命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#df%E5%91%BD%E4%BB%A4"><span class="toclist-text">df命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#iostat%E5%91%BD%E4%BB%A4"><span class="toclist-text">iostat命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#sar%E5%91%BD%E4%BB%A4"><span class="toclist-text">sar命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F"><span class="toclist-text">环境变量</span></a><ol class="toclist-child"><li class="toclist-item toclist-level-3"><a class="toclist-link" href="#PATH%E5%8F%98%E9%87%8F"><span class="toclist-text">PATH变量</span></a></li></ol></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E7%AC%A6%E5%8F%B7"><span class="toclist-text">$符号</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E5%8E%8B%E7%BC%A9%E8%A7%A3%E5%8E%8B"><span class="toclist-text">压缩解压</span></a><ol class="toclist-child"><li class="toclist-item toclist-level-3"><a class="toclist-link" href="#%E5%8E%8B%E7%BC%A9"><span class="toclist-text">压缩</span></a></li><li class="toclist-item toclist-level-3"><a class="toclist-link" href="#%E8%A7%A3%E5%8E%8B"><span class="toclist-text">解压</span></a></li></ol></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#su%E5%91%BD%E4%BB%A4"><span class="toclist-text">su命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#sudo%E5%91%BD%E4%BB%A4"><span class="toclist-text">sudo命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#chmod%E5%91%BD%E4%BB%A4"><span class="toclist-text">chmod命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#chown%E5%91%BD%E4%BB%A4"><span class="toclist-text">chown命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E7%94%A8%E6%88%B7%E7%BB%84%E7%AE%A1%E7%90%86"><span class="toclist-text">用户组管理</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E7%94%A8%E6%88%B7%E7%AE%A1%E7%90%86"><span class="toclist-text">用户管理</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#genenv%E5%91%BD%E4%BB%A4"><span class="toclist-text">genenv命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#env%E5%91%BD%E4%BB%A4"><span class="toclist-text">env命令</span></a></li></ol></li></ol></div></div></div></div><div class="sidebar animated"><div class="sidebar-top"><div class="logo-title"><div class="title"><img src="/images/avatar.png" style="width:220px;" alt="favicon"><h3 title=""><a href="/">imp的个人博客</a></h3><div class="description"><p>A simple blog</p></div></div><ul class="social-links"><li><a target="_blank" rel="noopener" href="https://github.com/Dimp07"><i class="fa fa-github"></i></a></li><li><a href="mailto:610634344@qq.com"><i class="fa fa-envelope"></i></a></li></ul></div><div class="toc-container in-sidebar animated fadeInDown"><details class="ltr" open><summary>目录</summary><div class="toclist-container"><div class="tocmenu"><ol class="toclist"><li class="toclist-item toclist-level-1"><a class="toclist-link"><span class="toclist-text">Linux基础命令</span></a><ol class="toclist-child"><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#Linux%E7%9A%84%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84"><span class="toclist-text">Linux的目录结构</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#ls%E5%91%BD%E4%BB%A4"><span class="toclist-text">ls命令</span></a><ol class="toclist-child"><li class="toclist-item toclist-level-3"><a class="toclist-link" href="#%E9%9A%90%E8%97%8F%E6%96%87%E4%BB%B6%E3%80%81%E6%96%87%E4%BB%B6%E5%A4%B9"><span class="toclist-text">隐藏文件、文件夹</span></a></li></ol></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#pwd%E5%91%BD%E4%BB%A4"><span class="toclist-text">pwd命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#cd%E5%91%BD%E4%BB%A4"><span class="toclist-text">cd命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#HOME%E7%9B%AE%E5%BD%95"><span class="toclist-text">HOME目录</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E7%9B%B8%E5%AF%B9%E8%B7%AF%E5%BE%84%E3%80%81%E7%BB%9D%E5%AF%B9%E8%B7%AF%E5%BE%84"><span class="toclist-text">相对路径、绝对路径</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E7%89%B9%E6%AE%8A%E8%B7%AF%E5%BE%84%E7%AC%A6"><span class="toclist-text">特殊路径符</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#mkdir%E5%91%BD%E4%BB%A4"><span class="toclist-text">mkdir命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#touch%E5%91%BD%E4%BB%A4"><span class="toclist-text">touch命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#cat%E5%91%BD%E4%BB%A4"><span class="toclist-text">cat命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#more%E5%91%BD%E4%BB%A4"><span class="toclist-text">more命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#cp%E5%91%BD%E4%BB%A4"><span class="toclist-text">cp命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#mv%E5%91%BD%E4%BB%A4"><span class="toclist-text">mv命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#rm%E5%91%BD%E4%BB%A4"><span class="toclist-text">rm命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#which%E5%91%BD%E4%BB%A4"><span class="toclist-text">which命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#find%E5%91%BD%E4%BB%A4"><span class="toclist-text">find命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#grep%E5%91%BD%E4%BB%A4"><span class="toclist-text">grep命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#wc%E5%91%BD%E4%BB%A4"><span class="toclist-text">wc命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E7%AE%A1%E9%81%93%E7%AC%A6"><span class="toclist-text">管道符|</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#echo%E5%91%BD%E4%BB%A4"><span class="toclist-text">echo命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E5%8F%8D%E5%BC%95%E5%8F%B7"><span class="toclist-text">&#96;反引号</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#tail%E5%91%BD%E4%BB%A4"><span class="toclist-text">tail命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#head%E5%91%BD%E4%BB%A4"><span class="toclist-text">head命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E9%87%8D%E5%AE%9A%E5%90%91%E7%AC%A6"><span class="toclist-text">重定向符</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#vi%E7%BC%96%E8%BE%91%E5%99%A8"><span class="toclist-text">vi编辑器</span></a><ol class="toclist-child"><li class="toclist-item toclist-level-3"><a class="toclist-link" href="#%E5%91%BD%E4%BB%A4%E6%A8%A1%E5%BC%8F%E5%BF%AB%E6%8D%B7%E9%94%AE"><span class="toclist-text">命令模式快捷键</span></a></li><li class="toclist-item toclist-level-3"><a class="toclist-link" href="#%E5%BA%95%E7%BA%BF%E5%91%BD%E4%BB%A4%E5%BF%AB%E6%8D%B7%E9%94%AE"><span class="toclist-text">底线命令快捷键</span></a></li></ol></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E5%91%BD%E4%BB%A4%E7%9A%84%E9%80%89%E9%A1%B9"><span class="toclist-text">命令的选项</span></a><ol class="toclist-child"><li class="toclist-item toclist-level-3"><a class="toclist-link" href="#%E6%9F%A5%E7%9C%8B%E5%91%BD%E4%BB%A4%E7%9A%84%E5%B8%AE%E5%8A%A9"><span class="toclist-text">查看命令的帮助</span></a></li><li class="toclist-item toclist-level-3"><a class="toclist-link" href="#%E6%9F%A5%E7%9C%8B%E5%91%BD%E4%BB%A4%E7%9A%84%E8%AF%A6%E7%BB%86%E6%89%8B%E5%86%8C"><span class="toclist-text">查看命令的详细手册</span></a></li></ol></li></ol></li><li class="toclist-item toclist-level-1"><a class="toclist-link"><span class="toclist-text">Linux常用操作</span></a><ol class="toclist-child"><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E8%BD%AF%E4%BB%B6%E5%AE%89%E8%A3%85"><span class="toclist-text">软件安装</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#systemctl"><span class="toclist-text">systemctl</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E8%BD%AF%E9%93%BE%E6%8E%A5"><span class="toclist-text">软链接</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E6%97%A5%E6%9C%9F"><span class="toclist-text">日期</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E6%97%B6%E5%8C%BA"><span class="toclist-text">时区</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#ntp"><span class="toclist-text">ntp</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#ip%E5%9C%B0%E5%9D%80"><span class="toclist-text">ip地址</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E4%B8%BB%E6%9C%BA%E5%90%8D"><span class="toclist-text">主机名</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E9%85%8D%E7%BD%AEVMware%E5%9B%BA%E5%AE%9AIP"><span class="toclist-text">配置VMware固定IP</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#ps%E5%91%BD%E4%BB%A4"><span class="toclist-text">ps命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#kill%E5%91%BD%E4%BB%A4"><span class="toclist-text">kill命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#nmap%E5%91%BD%E4%BB%A4"><span class="toclist-text">nmap命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#netstat%E5%91%BD%E4%BB%A4"><span class="toclist-text">netstat命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#ping%E5%91%BD%E4%BB%A4"><span class="toclist-text">ping命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#wget%E5%91%BD%E4%BB%A4"><span class="toclist-text">wget命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#curl%E5%91%BD%E4%BB%A4"><span class="toclist-text">curl命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#top%E5%91%BD%E4%BB%A4"><span class="toclist-text">top命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#df%E5%91%BD%E4%BB%A4"><span class="toclist-text">df命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#iostat%E5%91%BD%E4%BB%A4"><span class="toclist-text">iostat命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#sar%E5%91%BD%E4%BB%A4"><span class="toclist-text">sar命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F"><span class="toclist-text">环境变量</span></a><ol class="toclist-child"><li class="toclist-item toclist-level-3"><a class="toclist-link" href="#PATH%E5%8F%98%E9%87%8F"><span class="toclist-text">PATH变量</span></a></li></ol></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E7%AC%A6%E5%8F%B7"><span class="toclist-text">$符号</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E5%8E%8B%E7%BC%A9%E8%A7%A3%E5%8E%8B"><span class="toclist-text">压缩解压</span></a><ol class="toclist-child"><li class="toclist-item toclist-level-3"><a class="toclist-link" href="#%E5%8E%8B%E7%BC%A9"><span class="toclist-text">压缩</span></a></li><li class="toclist-item toclist-level-3"><a class="toclist-link" href="#%E8%A7%A3%E5%8E%8B"><span class="toclist-text">解压</span></a></li></ol></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#su%E5%91%BD%E4%BB%A4"><span class="toclist-text">su命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#sudo%E5%91%BD%E4%BB%A4"><span class="toclist-text">sudo命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#chmod%E5%91%BD%E4%BB%A4"><span class="toclist-text">chmod命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#chown%E5%91%BD%E4%BB%A4"><span class="toclist-text">chown命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E7%94%A8%E6%88%B7%E7%BB%84%E7%AE%A1%E7%90%86"><span class="toclist-text">用户组管理</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#%E7%94%A8%E6%88%B7%E7%AE%A1%E7%90%86"><span class="toclist-text">用户管理</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#genenv%E5%91%BD%E4%BB%A4"><span class="toclist-text">genenv命令</span></a></li><li class="toclist-item toclist-level-2"><a class="toclist-link" href="#env%E5%91%BD%E4%BB%A4"><span class="toclist-text">env命令</span></a></li></ol></li></ol></div></div></details></div></div><div class="footer"><div class="p"> <span>  </span><i class="fa fa-star"></i><span> imp</span></div><div class="by_farbox"><span>Powered by </span><a href="https://hexo.io/zh-cn/" target="_blank">Hexo </a><span> & </span><a href="https://github.com/Lhcfl/hexo-theme-anatolo" target="_blank">Anatolo </a></div><div class="beian"></div></div></div><div class="main animated fadeInDown"><div class="autopagerize_page_element"><div class="content"><div class="post-page"><div class="post animated"><div class="post-title"><h3><a>Linux基础命令</a></h3></div><div class="post-content"><p><h1>Linux基础命令</h1>
<h2 id="Linux的目录结构">Linux的目录结构</h2>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027214128.png" class="" title="image-20221027214128453">
<ul>
<li><code>/</code>，根目录是最顶级的目录了</li>
<li>Linux只有一个顶级目录：<code>/</code></li>
<li>路径描述的层次关系同样适用<code>/</code>来表示</li>
<li>/home/itheima/a.txt，表示根目录下的home文件夹内有itheima文件夹，内有a.txt</li>
</ul>
<h2 id="ls命令">ls命令</h2>
<p>功能：列出文件夹信息</p>
<p>语法：<code>ls [-l -h -a] [参数]</code></p>
<ul>
<li>参数：被查看的文件夹，不提供参数，表示查看当前工作目录</li>
<li>-l，以列表形式查看</li>
<li>-h，配合-l，以更加人性化的方式显示文件大小</li>
<li>-a，显示隐藏文件</li>
</ul>
<h3 id="隐藏文件、文件夹">隐藏文件、文件夹</h3>
<p>在Linux中以<code>.</code>开头的，均是隐藏的。</p>
<p>默认不显示出来，需要<code>-a</code>选项才可查看到。</p>
<h2 id="pwd命令">pwd命令</h2>
<p>功能：展示当前工作目录</p>
<p>语法：<code>pwd</code></p>
<h2 id="cd命令">cd命令</h2>
<p>功能：切换工作目录</p>
<p>语法：<code>cd [目标目录]</code></p>
<p>参数：目标目录，要切换去的地方，不提供默认切换到<code>当前登录用户HOME目录</code></p>
<h2 id="HOME目录">HOME目录</h2>
<p>每一个用户在Linux系统中都有自己的专属工作目录，称之为HOME目录。</p>
<ul>
<li>
<p>普通用户的HOME目录，默认在：<code>/home/用户名</code></p>
</li>
<li>
<p>root用户的HOME目录，在：<code>/root</code></p>
</li>
</ul>
<p>FinalShell登陆终端后，默认的工作目录就是用户的HOME目录</p>
<h2 id="相对路径、绝对路径">相对路径、绝对路径</h2>
<ul>
<li>
<p>相对路径，==非==<code>/</code>开头的称之为相对路径</p>
<p>相对路径表示以<code>当前目录</code>作为起点，去描述路径，如<code>test/a.txt</code>，表示当前工作目录内的test文件夹内的a.txt文件</p>
</li>
<li>
<p>绝对路径，==以==<code>/</code>开头的称之为绝对路径</p>
<p>绝对路径从<code>根</code>开始描述路径</p>
</li>
</ul>
<h2 id="特殊路径符">特殊路径符</h2>
<ul>
<li><code>.</code>，表示当前，比如./a.txt，表示当前文件夹内的<code>a.txt</code>文件</li>
<li><code>..</code>，表示上级目录，比如<code>../</code>表示上级目录，<code>../../</code>表示上级的上级目录</li>
<li><code>~</code>，表示用户的HOME目录，比如<code>cd ~</code>，即可切回用户HOME目录</li>
</ul>
<h2 id="mkdir命令">mkdir命令</h2>
<p>功能：创建文件夹</p>
<p>语法：<code>mkdir [-p] 参数</code></p>
<ul>
<li>参数：被创建文件夹的路径</li>
<li>选项：-p，可选，表示创建前置路径</li>
</ul>
<h2 id="touch命令">touch命令</h2>
<p>功能：创建文件</p>
<p>语法：<code>touch 参数</code></p>
<ul>
<li>参数：被创建的文件路径</li>
</ul>
<h2 id="cat命令">cat命令</h2>
<p>功能：查看文件内容</p>
<p>语法：<code>cat 参数</code></p>
<ul>
<li>参数：被查看的文件路径</li>
</ul>
<h2 id="more命令">more命令</h2>
<p>功能：查看文件，可以支持翻页查看</p>
<p>语法：<code>more 参数</code></p>
<ul>
<li>参数：被查看的文件路径</li>
<li>在查看过程中：
<ul>
<li><code>空格</code>键翻页</li>
<li><code>q</code>退出查看</li>
</ul>
</li>
</ul>
<h2 id="cp命令">cp命令</h2>
<p>功能：复制文件、文件夹</p>
<p>语法：<code>cp [-r] 参数1 参数2</code></p>
<ul>
<li>参数1，被复制的</li>
<li>参数2，要复制去的地方</li>
<li>选项：-r，可选，复制文件夹使用</li>
</ul>
<p>示例：</p>
<ul>
<li>cp a.txt b.txt，复制当前目录下a.txt为b.txt</li>
<li>cp a.txt test/，复制当前目录a.txt到test文件夹内</li>
<li>cp -r test test2，复制文件夹test到当前文件夹内为test2存在</li>
</ul>
<h2 id="mv命令">mv命令</h2>
<p>功能：移动文件、文件夹</p>
<p>语法：<code>mv 参数1 参数2</code></p>
<ul>
<li>参数1：被移动的</li>
<li>参数2：要移动去的地方，参数2如果不存在，则会进行改名</li>
</ul>
<h2 id="rm命令">rm命令</h2>
<p>功能：删除文件、文件夹</p>
<p>语法：<code>rm [-r -f] 参数...参数</code></p>
<ul>
<li>参数：支持多个，每一个表示被删除的，空格进行分隔</li>
<li>选项：-r，删除文件夹使用</li>
<li>选项：-f，强制删除，不会给出确认提示，一般root用户会用到</li>
</ul>
<blockquote>
<p>rm命令很危险，一定要注意，特别是切换到root用户的时候。</p>
</blockquote>
<h2 id="which命令">which命令</h2>
<p>功能：查看命令的程序本体文件路径</p>
<p>语法：<code>which 参数</code></p>
<ul>
<li>参数：被查看的命令</li>
</ul>
<h2 id="find命令">find命令</h2>
<p>功能：搜索文件</p>
<p>语法1按文件名搜索：<code>find 路径 -name 参数</code></p>
<ul>
<li>路径，搜索的起始路径</li>
<li>参数，搜索的关键字，支持通配符*， 比如：<code>*</code>test表示搜索任意以test结尾的文件</li>
</ul>
<h2 id="grep命令">grep命令</h2>
<p>功能：过滤关键字</p>
<p>语法：<code>grep [-n] 关键字 文件路径</code></p>
<ul>
<li>选项-n，可选，表示在结果中显示匹配的行的行号。</li>
<li>参数，关键字，必填，表示过滤的关键字，带有空格或其它特殊符号，建议使用””将关键字包围起来</li>
<li>参数，文件路径，必填，表示要过滤内容的文件路径，可作为内容输入端口</li>
</ul>
<blockquote>
<p>参数文件路径，可以作为管道符的输入</p>
</blockquote>
<h2 id="wc命令">wc命令</h2>
<p>功能：统计</p>
<p>语法：<code>wc [-c -m -l -w] 文件路径</code></p>
<ul>
<li>选项，-c，统计bytes数量</li>
<li>选项，-m，统计字符数量</li>
<li>选项，-l，统计行数</li>
<li>选项，-w，统计单词数量</li>
<li>参数，文件路径，被统计的文件，可作为内容输入端口</li>
</ul>
<blockquote>
<p>参数文件路径，可作为管道符的输入</p>
</blockquote>
<h2 id="管道符">管道符|</h2>
<p>写法：<code>|</code></p>
<p>功能：将符号左边的结果，作为符号右边的输入</p>
<p>示例：</p>
<p><code>cat a.txt | grep itheima</code>，将cat a.txt的结果，作为grep命令的输入，用来过滤<code>itheima</code>关键字</p>
<p>可以支持嵌套：</p>
<p><code>cat a.txt | grep itheima | grep itcast</code></p>
<h2 id="echo命令">echo命令</h2>
<p>功能：输出内容</p>
<p>语法：<code>echo 参数</code></p>
<ul>
<li>参数：被输出的内容</li>
</ul>
<h2 id="反引号">`反引号</h2>
<p>功能：被两个反引号包围的内容，会作为命令执行</p>
<p>示例：</p>
<ul>
<li>echo `pwd`，会输出当前工作目录</li>
</ul>
<h2 id="tail命令">tail命令</h2>
<p>功能：查看文件尾部内容</p>
<p>语法：<code>tail [-f] 参数</code></p>
<ul>
<li>参数：被查看的文件</li>
<li>选项：-f，持续跟踪文件修改</li>
</ul>
<h2 id="head命令">head命令</h2>
<p>功能：查看文件头部内容</p>
<p>语法：<code>head [-n] 参数</code></p>
<ul>
<li>参数：被查看的文件</li>
<li>选项：-n，查看的行数</li>
</ul>
<h2 id="重定向符">重定向符</h2>
<p>功能：将符号左边的结果，输出到右边指定的文件中去</p>
<ul>
<li><code>&gt;</code>，表示覆盖输出</li>
<li><code>&gt;&gt;</code>，表示追加输出</li>
</ul>
<h2 id="vi编辑器">vi编辑器</h2>
<h3 id="命令模式快捷键">命令模式快捷键</h3>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027215841.png" class="" title="image-20221027215841573">
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027215846.png" class="" title="image-20221027215846581">
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027215849.png" class="" title="image-20221027215849668">
<h3 id="底线命令快捷键">底线命令快捷键</h3>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027215858.png" class="" title="image-20221027215858967">
<h2 id="命令的选项">命令的选项</h2>
<p>我们学习的一系列Linux命令，它们所拥有的选项都是非常多的。</p>
<p>比如，简单的ls命令就有：-a -A -b -c -C -d -D -f -F -g -G -h -H -i -I -k -l -L -m -n -N -o -p -q -Q -r-R -s -S -t -T -u -U -v -w -x -X -1等选项，可以发现选项是极其多的。</p>
<p>课程中， 并不会将全部的选项都进行讲解，否则，一个ls命令就可能讲解2小时之久。</p>
<p>课程中，会对常见的选项进行讲解， 足够满足绝大多数的学习、工作场景。</p>
<h3 id="查看命令的帮助">查看命令的帮助</h3>
<p>可以通过：<code>命令 --help</code>查看命令的帮助手册</p>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027220005.png" class="" title="image-20221027220005610">
<h3 id="查看命令的详细手册">查看命令的详细手册</h3>
<p>可以通过：<code>man 命令</code>查看某命令的详细手册</p>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027220010.png" class="" title="image-20221027220009949">
<h1>Linux常用操作</h1>
<h2 id="软件安装">软件安装</h2>
<ul>
<li>CentOS系统使用：
<ul>
<li>yum [install remove search] [-y] 软件名称
<ul>
<li>install 安装</li>
<li>remove 卸载</li>
<li>search 搜索</li>
<li>-y，自动确认</li>
</ul>
</li>
</ul>
</li>
<li>Ubuntu系统使用
<ul>
<li>apt [install remove search] [-y] 软件名称
<ul>
<li>install 安装</li>
<li>remove 卸载</li>
<li>search 搜索</li>
<li>-y，自动确认</li>
</ul>
</li>
</ul>
</li>
</ul>
<blockquote>
<p>yum 和 apt 均需要root权限</p>
</blockquote>
<h2 id="systemctl">systemctl</h2>
<p>功能：控制系统服务的启动关闭等</p>
<p>语法：<code>systemctl start | stop | restart | disable | enable | status 服务名</code></p>
<ul>
<li>start，启动</li>
<li>stop，停止</li>
<li>status，查看状态</li>
<li>disable，关闭开机自启</li>
<li>enable，开启开机自启</li>
<li>restart，重启</li>
</ul>
<h2 id="软链接">软链接</h2>
<p>功能：创建文件、文件夹软链接（快捷方式）</p>
<p>语法：<code>ln -s 参数1 参数2</code></p>
<ul>
<li>参数1：被链接的</li>
<li>参数2：要链接去的地方（快捷方式的名称和存放位置）</li>
</ul>
<h2 id="日期">日期</h2>
<p>语法：<code>date [-d] [+格式化字符串]</code></p>
<ul>
<li>
<p>-d 按照给定的字符串显示日期，一般用于日期计算</p>
</li>
<li>
<p>格式化字符串：通过特定的字符串标记，来控制显示的日期格式</p>
<ul>
<li>%Y   年%y   年份后两位数字 (00…99)</li>
<li>%m   月份 (01…12)</li>
<li>%d   日 (01…31)</li>
<li>%H   小时 (00…23)</li>
<li>%M   分钟 (00…59)</li>
<li>%S   秒 (00…60)</li>
<li>%s   自 1970-01-01 00:00:00 UTC 到现在的秒数</li>
</ul>
</li>
</ul>
<p>示例：</p>
<ul>
<li>
<p>按照2022-01-01的格式显示日期</p>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027220514.png" class="" title="image-20221027220514640">
</li>
<li>
<p>按照2022-01-01 10:00:00的格式显示日期</p>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027220525.png" class="" title="image-20221027220525625">
</li>
<li>
<p>-d选项日期计算</p>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027220429.png" class="" title="image-20221027220429831">
<ul>
<li>
<p>支持的时间标记为：</p>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027220449.png" class="" title="image-20221027220449312">
</li>
</ul>
</li>
</ul>
<h2 id="时区">时区</h2>
<p>修改时区为中国时区</p>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027220554.png" class="" title="image-20221027220554654">
<h2 id="ntp">ntp</h2>
<p>功能：同步时间</p>
<p>安装：<code>yum install -y ntp</code></p>
<p>启动管理：<code>systemctl start | stop | restart | status | disable | enable ntpd</code></p>
<p>手动校准时间：<code>ntpdate -u ntp.aliyun.com</code></p>
<h2 id="ip地址">ip地址</h2>
<p>格式：a.b.c.d</p>
<ul>
<li>abcd为0~255的数字</li>
</ul>
<p>特殊IP：</p>
<ul>
<li>127.0.0.1，表示本机</li>
<li>0.0.0.0
<ul>
<li>可以表示本机</li>
<li>也可以表示任意IP（看使用场景）</li>
</ul>
</li>
</ul>
<p>查看ip：<code>ifconfig</code></p>
<h2 id="主机名">主机名</h2>
<p>功能：Linux系统的名称</p>
<p>查看：<code>hostname</code></p>
<p>设置：<code>hostnamectl set-hostname 主机名</code></p>
<h2 id="配置VMware固定IP">配置VMware固定IP</h2>
<ol>
<li>
<p>修改VMware网络，参阅PPT，图太多</p>
</li>
<li>
<p>设置Linux内部固定IP</p>
<p>修改文件：<code>/etc/sysconfig/network-scripts/ifcfg-ens33</code></p>
<p>示例文件内容：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">TYPE=&quot;Ethernet&quot;</span><br><span class="line">PROXY_METHOD=&quot;none&quot;</span><br><span class="line">BROWSER_ONLY=&quot;no&quot;</span><br><span class="line">BOOTPROTO=&quot;static&quot;			# 改为static，固定IP</span><br><span class="line">DEFROUTE=&quot;yes&quot;</span><br><span class="line">IPV4_FAILURE_FATAL=&quot;no&quot;</span><br><span class="line">IPV6INIT=&quot;yes&quot;</span><br><span class="line">IPV6_AUTOCONF=&quot;yes&quot;</span><br><span class="line">IPV6_DEFROUTE=&quot;yes&quot;</span><br><span class="line">IPV6_FAILURE_FATAL=&quot;no&quot;</span><br><span class="line">IPV6_ADDR_GEN_MODE=&quot;stable-privacy&quot;</span><br><span class="line">NAME=&quot;ens33&quot;</span><br><span class="line">UUID=&quot;1b0011cb-0d2e-4eaa-8a11-af7d50ebc876&quot;</span><br><span class="line">DEVICE=&quot;ens33&quot;</span><br><span class="line">ONBOOT=&quot;yes&quot;</span><br><span class="line">IPADDR=&quot;192.168.88.131&quot;		# IP地址，自己设置，要匹配网络范围</span><br><span class="line">NETMASK=&quot;255.255.255.0&quot;		# 子网掩码，固定写法255.255.255.0</span><br><span class="line">GATEWAY=&quot;192.168.88.2&quot;		# 网关，要和VMware中配置的一致</span><br><span class="line">DNS1=&quot;192.168.88.2&quot;			# DNS1服务器，和网关一致即可</span><br></pre></td></tr></table></figure>
</li>
</ol>
<h2 id="ps命令">ps命令</h2>
<p>功能：查看进程信息</p>
<p>语法：<code>ps -ef</code>，查看全部进程信息，可以搭配grep做过滤：<code>ps -ef | grep xxx</code></p>
<h2 id="kill命令">kill命令</h2>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027221303.png" class="" title="image-20221027221303037">
<h2 id="nmap命令">nmap命令</h2>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027221241.png" class="" title="image-20221027221241123">
<h2 id="netstat命令">netstat命令</h2>
<p>功能：查看端口占用</p>
<p>用法：<code>netstat -anp | grep xxx</code></p>
<h2 id="ping命令">ping命令</h2>
<p>测试网络是否联通</p>
<p>语法：<code>ping [-c num] 参数</code></p>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027221129.png" class="" title="image-20221027221129782">
<h2 id="wget命令">wget命令</h2>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027221149.png" class="" title="image-20221027221148964">
<h2 id="curl命令">curl命令</h2>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027221201.png" class="" title="image-20221027221201079">
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027221210.png" class="" title="image-20221027221210518">
<h2 id="top命令">top命令</h2>
<p>功能：查看主机运行状态</p>
<p>语法：<code>top</code>，查看基础信息</p>
<p>可用选项：</p>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027221340.png" class="" title="image-20221027221340729">
<p>交互式模式中，可用快捷键：</p>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027221354.png" class="" title="image-20221027221354137">
<h2 id="df命令">df命令</h2>
<p>查看磁盘占用</p>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027221413.png" class="" title="image-20221027221413787">
<h2 id="iostat命令">iostat命令</h2>
<p>查看CPU、磁盘的相关信息</p>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027221440.png" class="" title="image-20221027221439990">
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027221514.png" class="" title="image-20221027221514237">
<h2 id="sar命令">sar命令</h2>
<p>查看网络统计</p>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027221545.png" class="" title="image-20221027221545822">
<h2 id="环境变量">环境变量</h2>
<ul>
<li>临时设置：export 变量名=变量值</li>
<li>永久设置：
<ul>
<li>针对用户，设置用户HOME目录内：<code>.bashrc</code>文件</li>
<li>针对全局，设置<code>/etc/profile</code></li>
</ul>
</li>
</ul>
<h3 id="PATH变量">PATH变量</h3>
<p>记录了执行程序的搜索路径</p>
<p>可以将自定义路径加入PATH内，实现自定义命令在任意地方均可执行的效果</p>
<h2 id="符号">$符号</h2>
<p>可以取出指定的环境变量的值</p>
<p>语法：<code>$变量名</code></p>
<p>示例：</p>
<p><code>echo $PATH</code>，输出PATH环境变量的值</p>
<p><code>echo $&#123;PATH&#125;ABC</code>，输出PATH环境变量的值以及ABC</p>
<p>如果变量名和其它内容混淆在一起，可以使用${}</p>
<h2 id="压缩解压">压缩解压</h2>
<h3 id="压缩">压缩</h3>
<p><code>tar -zcvf 压缩包 被压缩1...被压缩2...被压缩N</code></p>
<ul>
<li>-z表示使用gzip，可以不写</li>
</ul>
<p><code>zip [-r] 参数1 参数2 参数N</code></p>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027221906.png" class="" title="image-20221027221906247">
<h3 id="解压">解压</h3>
<p><code>tar -zxvf 被解压的文件 -C 要解压去的地方</code></p>
<ul>
<li>-z表示使用gzip，可以省略</li>
<li>-C，可以省略，指定要解压去的地方，不写解压到当前目录</li>
</ul>
<p><code>unzip [-d] 参数</code></p>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027221939.png" class="" title="image-20221027221939899">
<h2 id="su命令">su命令</h2>
<p>切换用户</p>
<p>语法：<code>su [-] [用户]</code></p>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027222021.png" class="" title="image-20221027222021619">
<h2 id="sudo命令">sudo命令</h2>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027222035.png" class="" title="image-20221027222035337">
<p>比如：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">itheima ALL=(ALL)       NOPASSWD: ALL</span><br></pre></td></tr></table></figure>
<p>在visudo内配置如上内容，可以让itheima用户，无需密码直接使用<code>sudo</code></p>
<h2 id="chmod命令">chmod命令</h2>
<p>修改文件、文件夹权限</p>
<p>语法：<code>chmod [-R] 权限 参数</code></p>
<ul>
<li>
<p>权限，要设置的权限，比如755，表示：<code>rwxr-xr-x</code></p>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027222157.png" class="" title="image-20221027222157276">
</li>
<li>
<p>参数，被修改的文件、文件夹</p>
</li>
<li>
<p>选项-R，设置文件夹和其内部全部内容一样生效</p>
</li>
</ul>
<h2 id="chown命令">chown命令</h2>
<p>修改文件、文件夹所属用户、组</p>
<p>语法：<code>chown [-R] [用户][:][用户组] 文件或文件夹</code></p>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027222326.png" class="" title="image-20221027222326192">
<h2 id="用户组管理">用户组管理</h2>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027222354.png" class="" title="image-20221027222354498">
<h2 id="用户管理">用户管理</h2>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027222407.png" class="" title="image-20221027222407618">
<h2 id="genenv命令">genenv命令</h2>
<ul>
<li>
<p><code>getenv group</code>，查看系统全部的用户组</p>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027222446.png" class="" title="image-20221027222446514">
</li>
<li>
<p><code>getenv passwd</code>，查看系统全部的用户</p>
<img src="/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/20221027222512.png" class="" title="image-20221027222512274">
</li>
</ul>
<h2 id="env命令">env命令</h2>
<p>查看系统全部的环境变量</p>
<p>语法：<code>env</code></p>
</p></div><div class="post-footer"><div class="meta"><div class="info"><i class="fa fa-sun-o"></i><span class="date">2023-12-09</span><i class="fa fa-tag"></i><a class="tag" href="/tags/常用命令/" title="常用命令">常用命令 </a><span class="leancloud_visitors"></span><span>大约3126个字, 10分钟25秒读完</span></div></div></div></div><div class="share"><div class="evernote"><a class="fa fa-bookmark" href="" onclick="javascript:join_favorite()" ref="sidebar"></a></div><div class="weibo"><a class="fa fa-weibo" href="javascript:void((function(s,d,e){try{}catch(e){}var f='http://service.weibo.com/share/share.php?',u=d.location.href,p=['url=',e(u),'&amp;title=',e(d.title),'&amp;appkey=2924220432'].join('');function a(){if(!window.open([f,p].join(''),'mb',['toolbar=0,status=0,resizable=1,width=620,height=450,left=',(s.width-620)/2,',top=',(s.height-450)/2].join('')))u.href=[f,p].join('');};if(/Firefox/.test(navigator.userAgent)){setTimeout(a,0)}else{a()}})(screen,document,encodeURIComponent));"></a></div><div class="twitter"><a class="fa fa-twitter" target="_blank" rel="noopener" href="http://twitter.com/intent/tweet?text=%E5%88%86%E4%BA%AB%E6%96%87%E7%AB%A0%EF%BC%9A%0A%0Aimp%E7%9A%84%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2%20%C2%B7%20Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4%0Ahttp://example.com/2023/12/09/Linux%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4/%0A"></a></div></div><div class="pagination"><ul class="clearfix"><li class="pre pagbuttons"><a class="btn" role="navigation" href="/2023/12/09/MySQL%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/" title="MySQL概述">上一篇</a></li><li class="next pagbuttons"><a class="btn" role="navigation" href="/2023/12/09/%E5%A6%82%E4%BD%95%E9%AB%98%E6%95%88%E4%B8%94%E4%BC%98%E9%9B%85%E5%81%9A%E7%AC%94%E8%AE%B0%EF%BC%9F/" title="如何高效且优雅做笔记？">下一篇</a></li></ul></div><script src="/js/visitors.js"></script></div></div></div></div></main-outlet><script>(function(window){var INSIGHT_CONFIG={TRANSLATION:{POSTS:"文章",PAGES:"页面",CATEGORIES:"分类",TAGS:"标签",UNTITLED:"(无标题)",},CONTENT_URL:"/content.json",};window.INSIGHT_CONFIG=INSIGHT_CONFIG})(window);</script><script src="/js/insight.js" defer></script><div class="searchbox ins-search"><div class="searchbox-container ins-search-container"><div class="searchbox-input-wrapper"><input class="searchbox-input ins-search-input" type="text" placeholder="想要查找什么..."><span class="searchbox-close"><a class="fa fa-times-circle" onclick="closeWindow();"></a></span></div><div class="searchbox-result-wrapper ins-section-wrapper"><div class="ins-section-container"><p>Seraching...</p></div></div></div></div></body></html>